﻿<ValueConversion(GetType(Comic), GetType(BitmapImage))> _
Public Class comicArchiveTypeConverter
    Implements IValueConverter


    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        Dim x As Comic = value
        Dim r As ArchiveType
        If x Is Nothing Then
            r = ArchiveType.Unknown
        Else
            r = x.ArchiveType
        End If

        Dim bmp As New BitmapImage
        bmp.BeginInit()
        Select Case r
            Case ArchiveType.CBR
                bmp.UriSource = New Uri("pack://application:,,,/eComic2010;component/Resources/cbr_blue-014.png")
            Case ArchiveType.CBZ
                bmp.UriSource = New Uri("pack://application:,,,/eComic2010;component/Resources/cbz_blue-014.png")
            Case ArchiveType.PDF
            Case ArchiveType.OpenDirectory
                bmp.UriSource = New Uri("pack://application:,,,/LibraryFiles;component/Resources/folder-image.png")
            Case ArchiveType.Unknown
                bmp.UriSource = New Uri("pack://application:,,,/LibraryFiles;component/Resources/file-broken.png")
            Case Else
                bmp.UriSource = New Uri("pack://application:,,,/LibraryFiles;component/Resources/file-broken.png")
        End Select
        bmp.EndInit()
        Return bmp

    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Return Nothing
    End Function
End Class
